/**
 * Copyright (c) 2011 - 2012, Sohu Inc. All rights reserved.
 * @fileoverview Sohu  上传flash类
 * @author  bowen liu | liubowen082@163.com
 * @version 1.0 | 2013-04-13
 * @param
 * @example
 */
$require('mod.flvFlash');
LJS.define('mod.uploadFlv',function(ljs){
	
	
	var uploadFlv = function(op){
		this.swfUrl = 'http://test.jiajing.focus.cn/upload/al/js/admin/Upload.swf';
		this.uploadUrl = 'http://test.admin.jiajing.focus.cn/cases/ajax_upload_image';  //fragment/ajax_upload_image';
		this.w = 77;
		this.h = 22;
		this.box = op.box;
		this.id = "upload"+new Date().getTime();
		this.objectName = op.objectName;
		var that = this;
		$(this).on('uploadSuc',function(){
			
			
		})
	}
	
	uploadFlv.prototype = {
		create : function(){
		
			var t = this;
			//var str = writeFlash(t.id,t.swfUrl,t.w,t.h,t.fv);
			
			this.flv = new ljs.mod.flvFlash(this.box, this.swfUrl, {
                id: this.id,
                width: this.w,
                height: this.h,
                attrs: {
                    'allowNetworking': "all",
                    'allowScriptAccess': "always",
                    'wmode': "transparent",
                    'quality': "high"
                },
                flashvars: {
                    objectName:this.objectName,
					uploadUrl : this.uploadUrl
                },
                paras: {
                    'allowNetworking': "all",
                    'allowScriptAccess': "always",
                    'wmode': "transparent"
                }
            });
            this.flv.create()
		},
		getFlv : function(){
			return document.getElementById(this.id);
		},
		uploadCallback : function(flag,data){
			// “finish” "error"
			var that = this;
			switch(flag){
				case "finish" :  // 成功
					if (data.status == '100000') {
                        // 成功
                        $(that).trigger('uploadSuc',data)
                    }
                    else {
                        $(that).trigger('uploadErr',data)
                    }
				break;
				case "error" :  // 失败
					$(that).trigger('uploadErr',{msg:'io错误'})
				break;
			}
			
		}
	
	};
	return uploadFlv;
});
